<#-- 导入模版定义文件-->
<#include "../template/template_editPage.ftl">
<@edit title="下游用户信息管理">
    <#if (id)??>
        <#assign isEdit = true />
    <#else>
        <#assign isAdd = true />
    </#if>
<body class="input">

<script type="text/javascript">


    $().ready(function () {

        var $validateErrorContainer = $("#validateErrorContainer");
        var $validateErrorLabelContainer = $("#validateErrorContainer ul");
        var $validateForm = $("#inputForm");
        var $tab = $("#tab");

        // Tab效果
        $tab.tabs(".tabContent", {
            tabs:"input"
        });

        // 表单验证
        $validateForm.validate({
            errorContainer:$validateErrorContainer,
            errorLabelContainer:$validateErrorLabelContainer,
            wrapper:"li",
            errorClass:"validateError",
            ignoreTitle:true,
            rules:{
                "downInfo.userNo":{
                    required:true
                },
                "downInfo.userName":{
                    required:true
                },
                "downInfo.signTime":{
                    required:true
                },
                "downInfo.expireTime":{
                    required:true
                },
                "downInfo.secretKey":{
                    required:true
                },
                "downInfo.bindIPList":{
                required:true
                }
            },
            messages:{
                "downInfo.userNo":{
                    required:"用户编号不能为空！"
                },
                "downInfo.userName":{
                    required:"用户名称不能为空！"
                },
                "downInfo.signTime":{
                    required:"签约时间不能为空！"
                },
                "downInfo.expireTime":{
                    required:"签约到期时间不能为空！"
                },
                "downInfo.secretKey":{
                    required:"密钥不能为空！"
                },
                "downInfo.bindIPList":{
                    required:"下游ip地址不能为空！"
            },
            submitHandler:function (form) {
                //$(form).find(":submit").attr("disabled", true);
                    form.submit();
             }
            }


        });
        <#if actionErrors?? && (actionErrors?size > 0)>
            $.messager.show("提示信息", "<#list errorMessages as list>${list}<br></#list>", 2000);
        </#if>

        $('#submitId').click(function () {
            var validatorTi = validatorTime();
            var valiIp =  validateIps();
                return  validatorTi && valiIp;
        });

        $('#templateName').val('${downInfo.templateName!}');

    });

    function validatorTime() {
        $("#dateSpan").html("");
        $("#dateSpan2").html("");
        var startTime = document.getElementById("signTime").value;
        var endTime = document.getElementById("expireTime").value;
        return  compareTime(startTime, endTime);
    }

    function compareTime(startDate, endDate) {
        var startDateTemp = startDate.split(" ");
        var endDateTemp = endDate.split(" ");

        var arrStartDate = startDateTemp[0].split("-");
        var arrEndDate = endDateTemp[0].split("-");

        var arrStartTime = startDateTemp[1].split(":");
        var arrEndTime = endDateTemp[1].split(":");

        var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
        var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);

        if (allStartDate.getTime() > allEndDate.getTime()) {
            $("#dateSpan").html("签约时间不能大于签约到期时间！");
            $("#dateSpan2").html("签约到期时间不能小于签约时间！");
            return false;
        } else {
            return true;
        }
    }


    function validateIps() {
        $("#ipSpan").html("");
        var ipStr = $("#downIp").val();
        var ips = ipStr.split(";");
        var flag = true;
        if (ips.length > 0 && ips.length < 11) {
            for (var i = 0; i < ips.length; i++) {
                var ip = ips[i];
                flag = validateIp(ip);
                if(!flag){
                    break;
                }
            }
        } else{
            flag = false;
            $("#ipSpan").html("绑定的ip地址超过规定数！");
        }
        return flag;
    }

    function validateIp(ip) {
        var patrn = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;//正则表达式，\d为数字,{1,3}一位或为三位.
        if (!patrn.test(ip)) {
            $("#ipSpan").html("您输入的IP格式不正确，必须是000.000.000.000格式！");
            return false;
        }

        var laststr = ip.split(".");    //用.把字符串str分开
        var last_patrn = /^\d{1,3}$/;
        if (!last_patrn.test(laststr[3])) {
            $("#ipSpan").html("您输入的IP格式不正确，必须是000.000.000.000格式！");
            return false;
        }
        if (parseInt(laststr[0]) > 255 || parseInt(laststr[1]) > 255 || parseInt(laststr[2]) > 255 || parseInt(laststr[3]) > 255) { //判断IP每位的大小
            $("#ipSpan").html("您输入的IP范围不正确，必须是0~255之间！");
            return false;
        }
        return true;
    }



</script>

<div class="body">
<div class="inputBar">
    <h1><span class="icon">&nbsp;</span><#if isAdd??>添加下游用户信息<#else>编辑下游用户信息</#if></h1>
</div>
<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
    <div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
    <ul></ul>
</div>
<form id="inputForm" class="validate"
      action="<#if isAdd??>${web_base}/game/downstream_user!save.htm<#else>${web_base}/game/downstream_user!edit.htm</#if>"
      method="post">
    <input type="hidden" name="userNo" value="${userNo!}">
    <input type="hidden" name="userName" value="${userName!}">
    <input type="hidden" name="templateName" value="${templateName!}">
    <ul class="tab">
        <li>
            <input type="button" value="基本信息" hidefocus="true"/>
        </li>
    </ul>
    <table class="inputTable tabContent">

        <tr>
            <th>
                用户编号:
            </th>
            <#if isAdd??>
                <td>
                    <input type="text" name="downInfo.userNo"
                           class="formText {required: true, remote:'downstream_user!checkUserNo.htm', minlength: 2, maxlength: 20, messages: {remote: '用户名已存在,请重新输入!'}}"
                           value=""/>
                    <label class="requireField">*</label>
                </td>
            <#else>
                <td>
                    <input type="text" name="downInfo.userNo" class="formText {required: true}"
                           value="${downInfo.userNo!}" disabled="disabled" />
                    <input type="hidden" name="downInfo.userNo" class="formText {required: true}"
                           value="${downInfo.userNo!}"/>
                </td>
            </#if>
        </tr>

        <#if isAdd??>
            <tr>
                <th>
                    用户名称:
                </th>
                <td>
                    <input type="text" name="downInfo.userName" class="formText {required: true}"
                           value=""/>
                    <label class="requireField">*</label>
                </td>
            </tr>
        <#else>
            <input type="hidden" name="downInfo.id" class="formText {required: true}"
                   value="${downInfo.id!}"/>
             <tr>
                <th>
                    用户名称:
                </th>
                <td>
                    <input type="text" name="downInfo.userName" class="formText {required: true}"
                           value="${downInfo.userName!}"/>
                    <label class="requireField">*</label>
                </td>
            </tr>      
        </#if>

        <tr>
            <th>
                签约时间:
            </th>
            <td>
                <#if isAdd??>
                    <input type="text" id="signTime" name="downInfo.signTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${(downInfo.signTime)!}" class="Wdate">
                    <label class="requireField">*</label>
                    <span id="dateSpan" style="color: red"></span>
                <#else>
                    <input type="text" id="signTime" name="downInfo.signTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${(downInfo.signTime)!}" class="Wdate" disabled="disabled">
                    <input type="hidden" name="downInfo.signTime" class="formText {required: true}"
                           value="${downInfo.signTime!}"/>

                </#if>
            </td>
        </tr>

        <tr>
            <th>
                签约到期时间:
            </th>
            <td>
                <#if isAdd??>
                    <input type="text" id="expireTime" name="downInfo.expireTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${downInfo.expireTime!}" class="Wdate">
                    <label class="requireField">*</label>
                <#else>
                    <input type="text" id="expireTime" name="downInfo.expireTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${downInfo.expireTime!}" class="Wdate">
                    <span id="dateSpan2" style="color: red"></span>
                </#if>

            </td>
        </tr>
        <tr>
            <th>
                模版名称:
            </th>
            <td>
                <select name="downInfo.templateName" id="templateName" class="formText {required: false}">
                    <option value="" selected="selected">请选择...</option>
                    <#if templateNameList?? && (templateNameList?size gt 0)>
                        <#list templateNameList as name>
                            <option value="${name!}">
                            ${name!}
                            </option>
                        </#list>
                    </#if>
                </select>
            </td>
        </tr>
        <tr>
            <th>
                密钥:
            </th>
            <td>
                <input type="text" name="downInfo.secretKey" class="formText {required: true}"
                       value="${downInfo.secretKey!}"/>
                <label class="requireField">*</label>
            </td>
        </tr>
       
        <tr>
            <th>
                下游用户ip地址绑定:
            </th>
            <td>
                <input type="text" id="downIp" name="downInfo.bindIPList" class="formText {required: true}" onblur="validateIps();" value="${downInfo.bindIPList!}"/>
                <label class="requireField">*</label> <strong>(说明:可绑定多个ip,每个ip间以";"分隔,且最多只能绑定10个!)</strong>
                <span id="ipSpan" style="color: red"></span>
            </td>
        </tr>
        <tr>
            <th>
                退款通知地址:
            </th>
            <td>
                <input type="text" name="downInfo.refundUrl" class="formText"
                       value="${downInfo.refundUrl!}"/>
            </td>
        </tr>
        <tr>
            <th>
                货源变更通知地址:
            </th>
            <td>
                <input type="text" name="downInfo.goodsSourceModUrl" class="formText"
                       value="${downInfo.goodsSourceModUrl!}"/>
            </td>
        </tr>
        <tr>
            <th>
                腾讯Q币工号:
            </th>
            <td>
                <input type="text" name="downInfo.tencentAccount" class="formText"
                       value="${downInfo.tencentAccount!}"/>
            </td>
        </tr>
        <tr>
            <th>
              腾讯Q币工号密钥:
            </th>
            <td>
                <input type="text" name="downInfo.tencentSecretkey" class="formText"
                       value="${downInfo.tencentSecretkey!}"/>
            </td>
        </tr>
        <tr>
            <th>
              腾讯Q币工号优先级:
            </th>
            <td>
            	<#if downInfo.tencentPriority?? && downInfo.tencentPriority=="1">
	            	<select name="downInfo.tencentPriority" id="tencentPriority" class="formText {required: false}">
		            	<option value="1" selected="selected">IP优先</option>
		            	<option value="2">省域优先</option>
		            	<option value="">--请选择--</option>
	            	</select>
            	<#elseif downInfo.tencentPriority?? && downInfo.tencentPriority=="2">
            		<select name="downInfo.tencentPriority" id="tencentPriority" class="formText {required: false}">
		            	<option value="2" selected="selected">省域优先</option>
		            	<option value="1">IP优先</option>
		            	<option value="">--请选择--</option>
            		</select>
            	<#else>
            		<select name="downInfo.tencentPriority" id="tencentPriority" class="formText {required: false}">
		            	<option value="" selected="selected">--请选择--</option>
		            	<option value="1">IP优先</option>
		            	<option value="2">省域优先</option>
            		</select>
            	</#if>
            </td>
        </tr>
        <#if isAdd??>
            <tr>
                <th>
                    合同编号:
                </th>
                <td>
                    <input type="text" name="downInfo.contractNo" class="formText {required: false}"
                           value=""/>
                </td>
            </tr>
            <tr>
                <th>
                    单位编号:
                </th>
                <td>
                    <input type="text" name="downInfo.unitCode" class="formText {required: false}" value=""/>
                </td>
            </tr>
            <tr>
                <th>
                    单位名称:
                </th>
                <td>
                    <input type="text" name="downInfo.unitName" class="formText {required: false}" value=""/>
                </td>
            </tr>
        <#else>
            <input type="hidden" name="downInfo.contractNo" class="formText {required: false}"
                   value="${downInfo.contractNo!}"/>
            <input type="hidden" name="downInfo.unitCode" class="formText {required: false}"
                   value="${downInfo.unitCode!}"/>
            <input type="hidden" name="downInfo.unitName" class="formText {required: false}"
                   value="${downInfo.unitName!}"/>
        </#if>
        <tr>
            <th>
                备注：
            </th>
            <td>
                <textarea name="downInfo.remark" class="formTextarea">${(downInfo.remark)!}</textarea>
            </td>
        </tr>
    </table>
    <div class="buttonArea">
        <input type="submit" id="submitId" class="formButton" <#if isAdd??> value="添  加" <#else>
               value="更  新"</#if> hidefocus="true"/>&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回"
               hidefocus="true"/>
    </div>
</form>
</div>
</body>
</@edit>
